home *** CD-ROM | disk | FTP | other *** search
/ Windows Game Programming for Dummies (2nd Edition) / WinGamProgFD.iso / pc / DirectX SDK / DXSDK / samples / Multimedia / VBSamples / DirectShow / Editing / DexterVB / modRegistry.bas < prev    next >
Encoding:
BASIC Source File  |  2001-10-08  |  32.2 KB  |  623 lines

  1. Attribute VB_Name = "modRegistry"
  2. '*******************************************************************************
  3. '*       This is a part of the Microsoft DXSDK Code Samples.
  4. '*       Copyright (C) 1999-2001 Microsoft Corporation.
  5. '*       All rights reserved.
  6. '*       This source code is only intended as a supplement to
  7. '*       Microsoft Development Tools and/or SDK documentation.
  8. '*       See these sources for detailed information regarding the
  9. '*       Microsoft samples programs.
  10. '*******************************************************************************
  11. Option Explicit
  12. Option Base 0
  13. Option Compare Text
  14.  
  15.  
  16.  
  17. ' **************************************************************************************************************************************
  18. ' * PRIVATE INTERFACE- DATA STRUCTURES
  19. ' *
  20. ' *
  21.             Private Type ACL
  22.                     AclRevision As Byte
  23.                     Sbz1 As Byte
  24.                     AclSize As Integer
  25.                     AceCount As Integer
  26.                     Sbz2 As Integer
  27.             End Type
  28.             
  29.             Private Type FILETIME
  30.                     dwLowDateTime As Long
  31.                     dwHighDateTime As Long
  32.             End Type
  33.             
  34.             Private Type SECURITY_ATTRIBUTES
  35.                     nLength As Long
  36.                     lpSecurityDescriptor As Long
  37.                     bInheritHandle As Long
  38.             End Type
  39.             
  40.             Private Type SECURITY_DESCRIPTOR
  41.                     Revision As Byte
  42.                     Sbz1 As Byte
  43.                     Control As Long
  44.                     Owner As Long
  45.                     Group As Long
  46.                     Sacl As ACL
  47.                     Dacl As ACL
  48.             End Type
  49.             
  50.             
  51.             
  52.             
  53.             
  54. ' **************************************************************************************************************************************
  55. ' * PRIVATE INTERFACE- PREDEFINED CONSTANTS
  56. ' *
  57. ' *
  58.             Private Const MAX_PATH = 255
  59.             Private Const ERROR_SUCCESS = 0
  60.             
  61.             Private Const KEY_ALL_ACCESS = &H1F0000 '((STANDARD_RIGHTS_ALL Or KEY_QUERY_VALUE Or KEY_SET_VALUE Or KEY_CREATE_SUB_KEY Or KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY Or KEY_CREATE_LINK) And (Not SYNCHRONIZE))
  62.             Private Const KEY_CREATE_LINK = &H20
  63.             Private Const KEY_CREATE_SUB_KEY = &H4
  64.             Private Const KEY_ENUMERATE_SUB_KEYS = &H8
  65.             Private Const KEY_EVENT = &H1      ''"" Event contains key event record
  66.             Private Const KEY_EXECUTE = &H1  '((KEY_READ) And (Not SYNCHRONIZE))
  67.             Private Const KEY_FULL_MATCH_SEARCH = &H1
  68.             Private Const KEY_LENGTH_MASK = &HFFFF0000
  69.             Private Const KEY_NOTIFY = &H10
  70.             Private Const KEY_PARTIAL_MATCH_SEARCH = &H2
  71.             Private Const KEY_QUERY_VALUE = &H1
  72.             Private Const KEY_READ = KEY_QUERY_VALUE '((STANDARD_RIGHTS_READ Or KEY_QUERY_VALUE Or KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY) And (Not SYNCHRONIZE))
  73.             Private Const KEY_SET_VALUE = &H2
  74.             Private Const KEY_WRITE = KEY_SET_VALUE   '((STANDARD_RIGHTS_WRITE Or KEY_SET_VALUE Or KEY_CREATE_SUB_KEY) And (Not SYNCHRONIZE))
  75.             
  76.             Private Const REG_CREATED_NEW_KEY = &H1
  77.             Private Const REG_FULL_RESOURCE_DESCRIPTOR = 9
  78.             Private Const REG_LEGAL_CHANGE_FILTER = &H2 ' (REG_NOTIFY_CHANGE_NAME Or REG_NOTIFY_CHANGE_ATTRIBUTES Or REG_NOTIFY_CHANGE_LAST_SET Or REG_NOTIFY_CHANGE_SECURITY)
  79.             Private Const REG_LEGAL_OPTION = 0 '(REG_OPTION_RESERVED Or REG_OPTION_NON_VOLATILE Or REG_OPTION_VOLATILE Or REG_OPTION_CREATE_LINK Or REG_OPTION_BACKUP_RESTORE)
  80.             Private Const REG_NOTIFY_CHANGE_ATTRIBUTES = &H2
  81.             Private Const REG_NOTIFY_CHANGE_LAST_SET = &H4
  82.             Private Const REG_NOTIFY_CHANGE_NAME = &H1
  83.             Private Const REG_NOTIFY_CHANGE_SECURITY = &H8
  84.             Private Const REG_OPENED_EXISTING_KEY = &H2
  85.             Private Const REG_OPTION_BACKUP_RESTORE = 4
  86.             Private Const REG_OPTION_CREATE_LINK = 2
  87.             Private Const REG_OPTION_NON_VOLATILE = 0
  88.             Private Const REG_OPTION_RESERVED = 0
  89.             Private Const REG_OPTION_VOLATILE = 1
  90.             Private Const REG_REFRESH_HIVE = &H2
  91.             Private Const REG_RESOURCE_REQUIREMENTS_LIST = 10
  92.             Private Const REG_WHOLE_HIVE_VOLATILE = &H1
  93.             
  94.             
  95.             
  96.             
  97. ' **************************************************************************************************************************************
  98. ' * PRIVATE INTERFACE- WIN32 API DECLARATIONS
  99. ' *
  100. ' *
  101.             Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
  102.             Private Declare Function RegConnectRegistry Lib "advapi32.dll" Alias "RegConnectRegistryA" (ByVal lpMachineName As String, ByVal hKey As Long, phkResult As Long) As Long
  103.             Private Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
  104.             Private Declare Function RegCreateKeyEx Lib "advapi32.dll" Alias "RegCreateKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal Reserved As Long, ByVal lpClass As String, ByVal dwOptions As Long, ByVal samDesired As Long, lpSecurityAttributes As SECURITY_ATTRIBUTES, phkResult As Long, lpdwDisposition As Long) As Long
  105.             Private Declare Function RegDeleteKey Lib "advapi32.dll" Alias "RegDeleteKeyA" (ByVal hKey As Long, ByVal lpSubKey As String) As Long
  106.             Private Declare Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" (ByVal hKey As Long, ByVal lpValueName As String) As Long
  107.             Private Declare Function RegEnumKey Lib "advapi32.dll" Alias "RegEnumKeyA" (ByVal hKey As Long, ByVal dwIndex As Long, ByVal lpName As String, ByVal cbName As Long) As Long
  108.             Private Declare Function RegEnumKeyEx Lib "advapi32.dll" Alias "RegEnumKeyExA" (ByVal hKey As Long, ByVal dwIndex As Long, ByVal lpName As String, lpcbName As Long, ByVal lpReserved As Long, ByVal lpClass As String, lpcbClass As Long, lpftLastWriteTime As FILETIME) As Long
  109.             Private Declare Function RegEnumValue Lib "advapi32.dll" Alias "RegEnumValueA" (ByVal hKey As Long, ByVal dwIndex As Long, ByVal lpValueName As String, lpcbValueName As Long, ByVal lpReserved As Long, lpType As Long, lpData As Byte, lpcbData As Long) As Long
  110.             Private Declare Function RegFlushKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
  111.             Private Declare Function RegGetKeySecurity Lib "advapi32.dll" (ByVal hKey As Long, ByVal SecurityInformation As Long, pSecurityDescriptor As SECURITY_DESCRIPTOR, lpcbSecurityDescriptor As Long) As Long
  112.             Private Declare Function RegLoadKey Lib "advapi32.dll" Alias "RegLoadKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal lpFile As String) As Long
  113.             Private Declare Function RegNotifyChangeKeyValue Lib "advapi32.dll" (ByVal hKey As Long, ByVal bWatchSubtree As Long, ByVal dwNotifyFilter As Long, ByVal hEvent As Long, ByVal fAsynchronus As Long) As Long
  114.             Private Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
  115.             Private Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias "RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, ByVal samDesired As Long, phkResult As Long) As Long
  116.             Private Declare Function RegQueryInfoKey Lib "advapi32.dll" Alias "RegQueryInfoKeyA" (ByVal hKey As Long, ByVal lpClass As String, lpcbClass As Long, ByVal lpReserved As Long, lpcSubKeys As Long, lpcbMaxSubKeyLen As Long, lpcbMaxClassLen As Long, lpcValues As Long, lpcbMaxValueNameLen As Long, lpcbMaxValueLen As Long, lpcbSecurityDescriptor As Long, lpftLastWriteTime As FILETIME) As Long
  117.             Private Declare Function RegQueryValue Lib "advapi32.dll" Alias "RegQueryValueA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal lpValue As String, lpcbValue As Long) As Long
  118.             Private Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, lpData As Any, lpcbData As Long) As Long
  119.             Private Declare Function RegReplaceKey Lib "advapi32.dll" Alias "RegReplaceKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal lpNewFile As String, ByVal lpOldFile As String) As Long
  120.             Private Declare Function RegRestoreKey Lib "advapi32.dll" Alias "RegRestoreKeyA" (ByVal hKey As Long, ByVal lpFile As String, ByVal dwFlags As Long) As Long
  121.             Private Declare Function RegSaveKey Lib "advapi32.dll" Alias "RegSaveKeyA" (ByVal hKey As Long, ByVal lpFile As String, lpSecurityAttributes As SECURITY_ATTRIBUTES) As Long
  122.             Private Declare Function RegSetKeySecurity Lib "advapi32.dll" (ByVal hKey As Long, ByVal SecurityInformation As Long, pSecurityDescriptor As SECURITY_DESCRIPTOR) As Long
  123.             Private Declare Function RegSetValue Lib "advapi32.dll" Alias "RegSetValueA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal dwType As Long, ByVal lpData As String, ByVal cbData As Long) As Long
  124.             Private Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, lpData As Any, ByVal cbData As Long) As Long
  125.             Private Declare Function RegUnLoadKey Lib "advapi32.dll" Alias "RegUnLoadKeyA" (ByVal hKey As Long, ByVal lpSubKey As String) As Long
  126.             
  127.  
  128.  
  129.  
  130. ' **************************************************************************************************************************************
  131. ' * PUBLIC INTERFACE- ENUMERATIONS
  132. ' *
  133. ' *
  134.             Public Enum hKey
  135.             HKEY_CLASSES_ROOT = &H80000000
  136.             HKEY_CURRENT_CONFIG = &H80000005
  137.             HKEY_CURRENT_USER = &H80000001
  138.             HKEY_DYN_DATA = &H80000006
  139.             HKEY_LOCAL_MACHINE = &H80000002
  140.             HKEY_PERFORMANCE_DATA = &H80000004
  141.             HKEY_USERS = &H80000003
  142.             End Enum
  143.             
  144.             
  145.             Public Enum EntryFormat
  146.             REG_BINARY = 0                              'Binary data in any form.
  147.             REG_DWORD = 1                              'A 32-bit number.
  148.             REG_DWORD_LITTLE_ENDIAN = 2  'A 32-bit number in little-endian format. This is equivalent to REG_DWORD.
  149.             REG_DWORD_BIG_ENDIAN = 3       'A 32-bit number in big-endian format.
  150.             REG_EXPAND_SZ = 4                       'A null-terminated string that contains unexpanded references to environment variables
  151.             REG_LINK = 5                                   'A Unicode symbolic link.
  152.             REG_MULTI_SZ = 6                          'An array of null-terminated strings, terminated by two null characters.
  153.             REG_NONE = 7                                 'No defined value type.
  154.             REG_RESOURCE_LIST = 8              'A device-driver resource list.
  155.             REG_SZ = 9                                      'A null-terminated string. It will be a Unicode or ANSI string depending on whether you use Unicode or ANSI.
  156.             End Enum
  157.  
  158.  
  159.  
  160. ' **************************************************************************************************************************************
  161. ' * PUBLIC INTERFACE- PROCEDURES
  162. ' *
  163. ' *
  164.             ' ******************************************************************************************************************************
  165.             ' * procedure name: Registry_CreateKey
  166.             ' * procedure description:   Create's a new key in the window's system registry.
  167.             ' *                                        Returns the registry error code on failure, the new handle on success
  168.             ' ******************************************************************************************************************************
  169.             Public Function Registry_CreateKey(MainKey As hKey, SubKey As String) As Long
  170.             Dim nRet As Long, nDisposition As Long, nKey As Long
  171.             Dim sSubKey As String, nSubStart As Integer, SecAttr As SECURITY_ATTRIBUTES
  172.             On Local Error GoTo ErrLine
  173.             
  174.             'check to ensure subkey is valid
  175.             If Len(SubKey) = 0 Then Exit Function
  176.             
  177.             'check to ensure the mainkey is valid
  178.             If CLng(MainKey) = 0 Then Exit Function
  179.             
  180.             'convert to upper case
  181.             SubKey = UCase(SubKey)
  182.             
  183.             'check for backslash
  184.             If Left(SubKey, 1) = "\" Then SubKey = Mid(SubKey, 2, Len(SubKey))
  185.             
  186.             'Create a new Key
  187.             nRet = RegCreateKeyEx(CLng(MainKey), SubKey, 0, vbNullString, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, SecAttr, nKey, nDisposition)
  188.             
  189.             If nKey <> 0 Then  'the key was created successfully; return the handle.
  190.                RegCloseKey (nKey)
  191.                Registry_CreateKey = nRet
  192.             Else 'an error occured, return zero and exit.
  193.                Registry_CreateKey = 0
  194.                Exit Function
  195.             End If
  196.             Exit Function
  197.                         
  198. ErrLine:
  199.  
  200.             Err.Clear
  201.             If nKey <> 0 Then RegCloseKey (nKey) 'the key is open close it and exit
  202.             Exit Function
  203.             End Function
  204.             
  205.             
  206.             
  207.             ' ******************************************************************************************************************************
  208.             ' * procedure name: Registry_DeleteKey
  209.             ' * procedure description:   deletes an existing key in the window's system registry.
  210.             ' *
  211.             ' ******************************************************************************************************************************
  212.             Public Function Registry_DeleteKey(MainKey As hKey, SubKey As String) As Long
  213.             On Local Error GoTo ErrLine
  214.             
  215.             'check to ensure subkey is valid
  216.             If Len(SubKey) = 0 Then Exit Function
  217.             
  218.             'check to ensure the mainkey is valid
  219.             If CLng(MainKey) = 0 Then Exit Function
  220.             
  221.             'convert to upper case
  222.             SubKey = UCase(SubKey)
  223.             
  224.             'check for backslash
  225.             If Left(SubKey, 1) = "\" Then SubKey = Mid(SubKey, 2, Len(SubKey))
  226.             
  227.             'delete the key from the registry; if WinNT this will fail if the key has subkeys
  228.             Registry_DeleteKey = RegDeleteKey(CLng(MainKey), SubKey)
  229.             'exit
  230.             Exit Function
  231.             
  232.             
  233.             
  234. ErrLine:
  235.             Err.Clear
  236.             Exit Function
  237.             End Function
  238.             
  239.             
  240.             
  241.             ' ******************************************************************************************************************************
  242.             ' * procedure name: Registry_DoesKeyExist
  243.             ' * procedure description:   Checks to ensure a key does in fact exist
  244.             ' *
  245.             ' ******************************************************************************************************************************
  246.             Public Function Registry_DoesKeyExist(MainKey As hKey, SubKey As String) As Boolean
  247.             Dim nSubHandle As Long
  248.             On Local Error GoTo ErrLine
  249.             
  250.             'check to ensure subkey is valid
  251.             If Len(SubKey) = 0 Then Exit Function
  252.             
  253.             'check to ensure the mainkey is valid
  254.             If CLng(MainKey) = 0 Then Exit Function
  255.             
  256.             'convert to upper case
  257.             SubKey = UCase(SubKey)
  258.             
  259.             'check for backslash
  260.             If Left(SubKey, 1) = "\" Then SubKey = Mid(SubKey, 2, Len(SubKey))
  261.             
  262.             
  263.             'open the key for read access
  264.             RegOpenKeyEx CLng(MainKey), SubKey, 0, KEY_READ, nSubHandle
  265.             
  266.             'return and exit
  267.             If nSubHandle <> 0 Then
  268.                Registry_DoesKeyExist = True
  269.                RegCloseKey (nSubHandle)
  270.             Else:  Registry_DoesKeyExist = False
  271.             End If
  272.             Exit Function
  273.             
  274.             
  275. ErrLine:
  276.             Err.Clear
  277.             Exit Function
  278.             End Function
  279.             
  280.             
  281.             
  282.             ' ******************************************************************************************************************************
  283.             ' * procedure name: Registry_CreateEntry
  284.             ' * procedure description:   Creates an entry for the user
  285.             ' *
  286.             ' ******************************************************************************************************************************
  287.             Public Function Registry_CreateEntry(MainKey As hKey, SubKey As String, strEntry As String, Optional strEntryValue As String = vbNullString, Optional Format As EntryFormat = REG_SZ) As Long
  288.             Dim nSubHandle As Long, nRet As Long, strBuffer As String
  289.             On Local Error GoTo ErrLine
  290.             'check to ensure subkey is valid
  291.             If Len(SubKey) = 0 Then Exit Function
  292.             
  293.             'check to ensure the mainkey is valid
  294.             If CLng(MainKey) = 0 Then Exit Function
  295.             
  296.             'check to ensure the entry's string data is null-terminated
  297.             If Right(strEntryValue, 1) <> vbNullChar Then strEntryValue = (strEntryValue & vbNullChar)
  298.             
  299.             'form a buffer for the entry's string data to be passed the the api
  300.             strBuffer = String(Len(strEntryValue), 0)
  301.             strBuffer = strEntryValue
  302.             
  303.             'convert to upper case
  304.             SubKey = UCase(SubKey)
  305.             
  306.             'check for backslash
  307.             If Left(SubKey, 1) = "\" Then SubKey = Mid(SubKey, 2, Len(SubKey))
  308.             
  309.             'open the key with update value access; this should be all that is required to append an entry..
  310.             nRet = RegOpenKeyEx(CLng(MainKey), SubKey, 0, KEY_SET_VALUE, nSubHandle)
  311.             
  312.             'check api return for success before continueing
  313.             If nRet <> ERROR_SUCCESS Or nSubHandle = 0 Then Exit Function
  314.             
  315.             'set the new entry value to the key
  316.             Registry_CreateEntry = RegSetValueEx(nSubHandle, strEntry, 0, CLng(Format), ByVal strBuffer, Len(strBuffer) + 1)
  317.             
  318.             'close the key handle
  319.             RegCloseKey (nSubHandle)
  320.             
  321.             'exit
  322.             Exit Function
  323.             
  324.             
  325.             
  326. ErrLine:
  327.             Err.Clear
  328.             Exit Function
  329.             End Function
  330.             
  331.             
  332.             ' ******************************************************************************************************************************
  333.             ' * procedure name: Registry_DeleteEntry
  334.             ' * procedure description:   Delete's an entry in a registry subkey
  335.             ' *
  336.             ' ******************************************************************************************************************************
  337.             Public Function Registry_DeleteEntry(MainKey As hKey, SubKey As String, strEntry As String) As Long
  338.             Dim nSubHandle, nRet As Long
  339.             On Local Error GoTo ErrLine
  340.             'check to ensure subkey is valid
  341.             If Len(SubKey) = 0 Then Exit Function
  342.             
  343.             'check to ensure the mainkey is valid
  344.             If CLng(MainKey) = 0 Then Exit Function
  345.             
  346.             'check to ensure the entryname is valid
  347.             If strEntry = vbNullString Then Exit Function
  348.             'check that it is null terminated
  349.             If Right(strEntry, 1) <> vbNullChar Then strEntry = (strEntry & vbNullChar)
  350.             
  351.             'convert to upper case
  352.             SubKey = UCase(SubKey)
  353.             
  354.             'check for backslash
  355.             If Left(SubKey, 1) = "\" Then SubKey = Mid(SubKey, 2, Len(SubKey))
  356.             
  357.             'open the key with local write access; this should be all that is required to append an entry..
  358.             nRet = RegOpenKeyEx(CLng(MainKey), SubKey, 0, KEY_WRITE, nSubHandle)
  359.             
  360.             'check api return before continueing
  361.             If nRet <> ERROR_SUCCESS Or nSubHandle = 0 Then Exit Function
  362.             
  363.             'attempt to delete the entry and return the result
  364.             Registry_DeleteEntry = RegDeleteValue(nSubHandle, strEntry)
  365.             
  366.             'close the open key handle and exit
  367.             RegCloseKey (nSubHandle)
  368.             Exit Function
  369.             
  370.             
  371.             
  372. ErrLine:
  373.             Err.Clear
  374.             Exit Function
  375.             End Function
  376.             
  377.             
  378.             ' ******************************************************************************************************************************
  379.             ' * procedure name: Registry_UpdateEntry
  380.             ' * procedure description:   Updates the value of an entry within a subkey; this function will create it if it does not exist.
  381.             ' *
  382.             ' ******************************************************************************************************************************
  383.             Public Function Registry_UpdateEntry(MainKey As hKey, SubKey As String, strEntry As String, strEntryValue As String, Optional Format As EntryFormat = REG_SZ) As Long
  384.             Dim nSubHandle As Long, nRet As Long, strBuffer As String
  385.             On Local Error GoTo ErrLine
  386.             'check to ensure subkey is valid
  387.             If Len(SubKey) = 0 Then Exit Function
  388.             
  389.             'check to ensure the mainkey is valid
  390.             If CLng(MainKey) = 0 Then Exit Function
  391.             
  392.             'check to ensure the entry's string data is null-terminated
  393.             If Right(strEntryValue, 1) <> vbNullChar Then strEntryValue = (strEntryValue & vbNullChar)
  394.             
  395.             'form a buffer for the entry's string data to be passed the the api
  396.             strBuffer = String(Len(strEntryValue), 0)
  397.             strBuffer = strEntryValue
  398.             
  399.             'convert to upper case
  400.             SubKey = UCase(SubKey)
  401.             
  402.             'check for backslash
  403.             If Left(SubKey, 1) = "\" Then SubKey = Mid(SubKey, 2, Len(SubKey))
  404.             
  405.             'open the key with update value access; this should be all that is required to append an entry..
  406.             nRet = RegOpenKeyEx(CLng(MainKey), SubKey, 0, KEY_SET_VALUE, nSubHandle)
  407.             
  408.             'check api return for success before continueing
  409.             If nRet <> ERROR_SUCCESS Or nSubHandle = 0 Then Exit Function
  410.             
  411.             'set the new entry value to the key
  412.             Registry_UpdateEntry = RegSetValueEx(nSubHandle, strEntry, 0, CLng(Format), ByVal strBuffer, Len(strBuffer) + 1)
  413.             
  414.             'close the key handle
  415.             RegCloseKey (nSubHandle)
  416.             
  417.             'exit
  418.             Exit Function
  419.             
  420.             
  421.             
  422. ErrLine:
  423.             Err.Clear
  424.             Exit Function
  425.             End Function
  426.             
  427.             
  428.             
  429.             ' ******************************************************************************************************************************
  430.             ' * procedure name: Registry_QueryEntryValue
  431.             ' * procedure description:   Returns the value of an entry; on error returns default
  432.             ' *
  433.             ' ******************************************************************************************************************************
  434.             Public Function Registry_QueryEntryValue(MainKey As hKey, SubKey As String, strEntry As String, Optional Default As String = vbNullString) As String
  435.             Dim nSubHandle As Long, nFileTime As FILETIME
  436.             Dim nRet As Long, strBuffer As String, nMaxValueLen As Long
  437.             On Local Error GoTo ErrLine
  438.             
  439.             'check to ensure subkey is valid
  440.             If Len(SubKey) = 0 Then Exit Function
  441.             
  442.             'check to ensure the mainkey is valid
  443.             If CLng(MainKey) = 0 Then Exit Function
  444.             
  445.             'Check to ensure the entry is valid
  446.             If strEntry = vbNullString Then Exit Function
  447.             
  448.             'convert to upper case
  449.             SubKey = UCase(SubKey)
  450.             
  451.             'check for backslash
  452.             If Left(SubKey, 1) = "\" Then SubKey = Mid(SubKey, 2, Len(SubKey))
  453.             
  454.             'open the key and get a handle
  455.             nRet = RegOpenKeyEx(CLng(MainKey), SubKey, 0, KEY_READ, nSubHandle)
  456.             
  457.             'check the api return
  458.             If nRet <> ERROR_SUCCESS Or nSubHandle = 0 Then Exit Function
  459.             
  460.             'get the length of the largest given entry in the subkey so that we may be able to form a properly sized buffer
  461.             nRet = RegQueryInfoKey(nSubHandle, vbNullString, 0, 0, 0, 0, 0, 0, 0, nMaxValueLen, 0, nFileTime)
  462.             
  463.             'set up a properly sized buffer given the known largest entry value size; set to MAX_PATH in case of last api failure
  464.             If nMaxValueLen < 255 Then nMaxValueLen = 255
  465.             strBuffer = String(nMaxValueLen, 0)
  466.             
  467.             'query the key for an entry value
  468.             nMaxValueLen = Len(strBuffer) + 1
  469.             nRet = RegQueryValueEx(nSubHandle, strEntry, 0, 0, ByVal strBuffer, nMaxValueLen)
  470.             If nRet = ERROR_SUCCESS Then
  471.                 strBuffer = Left(strBuffer, nMaxValueLen)
  472.                 Registry_QueryEntryValue = strBuffer
  473.             Else: Registry_QueryEntryValue = Default
  474.             End If
  475.             
  476.             'close the handle, return the value and exit
  477.             RegCloseKey (nSubHandle)
  478.             Exit Function
  479.             
  480.             
  481.             
  482. ErrLine:
  483.             Err.Clear
  484.             Exit Function
  485.             End Function
  486.             
  487.             
  488.             
  489.             ' ******************************************************************************************************************************
  490.             ' * procedure name: Registry_QueryEntryType
  491.             ' * procedure description:   Returns the type of data an entry contains.
  492.             ' *
  493.             ' ******************************************************************************************************************************
  494.             Public Function Registry_QueryEntryType(MainKey As hKey, SubKey As String, strEntry As String) As EntryFormat
  495.             Dim nType As Long, nSubHandle As Long, nRet As Long
  496.             On Local Error GoTo ErrLine
  497.             'check to ensure subkey is valid
  498.             If Len(SubKey) = 0 Then Exit Function
  499.             
  500.             'check to ensure the mainkey is valid
  501.             If CLng(MainKey) = 0 Then Exit Function
  502.             
  503.             'Check to ensure the entry is valid
  504.             If strEntry = vbNullString Then Exit Function
  505.             
  506.             'convert to upper case
  507.             SubKey = UCase(SubKey)
  508.             
  509.             'check for backslash
  510.             If Left(SubKey, 1) = "\" Then SubKey = Mid(SubKey, 2, Len(SubKey))
  511.             
  512.             'open the key for read access
  513.             nRet = RegOpenKeyEx(CLng(MainKey), SubKey, 0, KEY_READ, nSubHandle)
  514.             
  515.             'check return on api call
  516.             If nRet <> ERROR_SUCCESS Or nSubHandle = 0 Then Exit Function
  517.             
  518.             'query the entry in the key for any given type information
  519.             nRet = RegQueryValueEx(nSubHandle, ByVal strEntry, 0, nType, 0, 0)
  520.             
  521.             Select Case nType
  522.                   Case 0: Registry_QueryEntryType = REG_BINARY
  523.                   Case 1: Registry_QueryEntryType = REG_DWORD
  524.                   Case 2: Registry_QueryEntryType = REG_DWORD_BIG_ENDIAN
  525.                   Case 3: Registry_QueryEntryType = REG_DWORD_LITTLE_ENDIAN
  526.                   Case 4: Registry_QueryEntryType = REG_EXPAND_SZ
  527.                   Case 5: Registry_QueryEntryType = REG_LINK
  528.                   Case 6: Registry_QueryEntryType = REG_MULTI_SZ
  529.                   Case 7: Registry_QueryEntryType = REG_NONE
  530.                   Case 8: Registry_QueryEntryType = REG_RESOURCE_LIST
  531.                   Case 9: Registry_QueryEntryType = REG_SZ
  532.             End Select
  533.             
  534.             'exit
  535.             Exit Function
  536.                         
  537. ErrLine:
  538.  
  539.             Err.Clear
  540.             Exit Function
  541.             End Function
  542.             
  543.             
  544.             
  545.             ' ******************************************************************************************************************************
  546.             ' * procedure name: Registry_DoesEntryExist
  547.             ' * procedure description:   Checks to ensure an entry does in fact exist
  548.             ' *
  549.             ' ******************************************************************************************************************************
  550.             Public Function Registry_DoesEntryExist(MainKey As hKey, SubKey As String, strEntry As String) As Boolean
  551.             Dim nType As Long, nSubHandle As Long, nRet As Long
  552.             On Local Error GoTo ErrLine
  553.             'check to ensure subkey is valid
  554.             If Len(SubKey) = 0 Then Exit Function
  555.             
  556.             'check to ensure the mainkey is valid
  557.             If CLng(MainKey) = 0 Then Exit Function
  558.             
  559.             'Check to ensure the entry is valid
  560.             If strEntry = vbNullString Then Exit Function
  561.             
  562.             'convert to upper case
  563.             SubKey = UCase(SubKey)
  564.             
  565.             'check for backslash
  566.             If Left(SubKey, 1) = "\" Then SubKey = Mid(SubKey, 2, Len(SubKey))
  567.             
  568.             'open the key for read access
  569.             nRet = RegOpenKeyEx(CLng(MainKey), SubKey, 0, KEY_READ, nSubHandle)
  570.             
  571.             'check return on api call
  572.             If nRet <> ERROR_SUCCESS Or nSubHandle = 0 Then Exit Function
  573.             
  574.             'query the entry in the key for any given type information
  575.             nRet = RegQueryValueEx(nSubHandle, ByVal strEntry, 0, nType, 0, 0)
  576.             
  577.             'verify api return
  578.             If nRet > 0 Then
  579.                Registry_DoesEntryExist = True
  580.             Else
  581.                Registry_DoesEntryExist = False
  582.             End If
  583.             
  584.             'exit
  585.             Exit Function
  586.             
  587. ErrLine:
  588.             Err.Clear
  589.             Exit Function
  590.             End Function
  591.             
  592.             
  593.  
  594.  
  595. ' **************************************************************************************************************************************
  596. ' * PRIVATE INTERFACE- PROCEDURES
  597. ' *
  598. ' *
  599.             ' ******************************************************************************************************************************
  600.             ' * procedure name: Reg_KeyToStr
  601.             ' * procedure description:   Returns a string denoteing the current key handle; this can be used later
  602.             ' *                                        if you decide to extend remote registry access functionality into this module.
  603.             ' ******************************************************************************************************************************
  604.             Private Function Reg_KeyToStr(nKey As Long) As String
  605.             On Local Error GoTo ErrLine
  606.             
  607.             Select Case nKey
  608.                   Case HKEY_CLASSES_ROOT: Reg_KeyToStr = "HKEY_CLASSES_ROOT"
  609.                   Case HKEY_CURRENT_CONFIG: Reg_KeyToStr = "HKEY_CURRENT_CONFIG"
  610.                   Case HKEY_CURRENT_USER: Reg_KeyToStr = "HKEY_CURRENT_USER"
  611.                   Case HKEY_LOCAL_MACHINE: Reg_KeyToStr = "HKEY_LOCAL_MACHINE"
  612.                   Case HKEY_USERS: Reg_KeyToStr = "HKEY_USERS"
  613.                   Case HKEY_DYN_DATA: Reg_KeyToStr = "HKEY_DYN_DATA"
  614.                   Case HKEY_PERFORMANCE_DATA: Reg_KeyToStr = "HKEY_PERFORMANCE_DATA"
  615.                   Case Else: Reg_KeyToStr = vbNullString
  616.             End Select
  617.             Exit Function
  618.             
  619. ErrLine:
  620.             Err.Clear
  621.             Exit Function
  622.             End Function
  623.